#!/usr/bin/env python3
"""
Create Test Image Script
创建测试图像脚本
"""

import os
from PIL import Image, ImageDraw, ImageFont
from pathlib import Path

def create_test_image():
    """创建一个简单的测试图像"""
    # 创建图像
    width, height = 400, 300
    image = Image.new('RGB', (width, height), color='lightblue')
    
    # 创建绘图对象
    draw = ImageDraw.Draw(image)
    
    # 绘制一些简单的图形
    # 绘制矩形
    draw.rectangle([50, 50, 150, 100], fill='red', outline='black', width=2)
    
    # 绘制圆形
    draw.ellipse([200, 50, 300, 100], fill='green', outline='black', width=2)
    
    # 绘制三角形
    draw.polygon([(350, 50), (400, 100), (300, 100)], fill='yellow', outline='black')
    
    # 绘制线条
    draw.line([(50, 150), (350, 150)], fill='purple', width=3)
    
    # 添加文字
    try:
        # 尝试使用默认字体
        font = ImageFont.load_default()
        draw.text((50, 200), "IGRAG Test Image", fill='black', font=font)
        draw.text((50, 220), "This is a test image for", fill='black', font=font)
        draw.text((50, 240), "image retrieval and generation", fill='black', font=font)
    except:
        # 如果字体加载失败，使用默认字体
        draw.text((50, 200), "IGRAG Test Image", fill='black')
        draw.text((50, 220), "This is a test image for", fill='black')
        draw.text((50, 240), "image retrieval and generation", fill='black')
    
    return image

def main():
    """主函数"""
    # 获取项目根目录
    project_root = Path(__file__).parent.parent
    input_dir = project_root / "input"
    
    # 确保input目录存在
    input_dir.mkdir(exist_ok=True)
    
    # 创建测试图像
    test_image = create_test_image()
    
    # 保存图像
    test_image_path = input_dir / "test_image.jpg"
    test_image.save(test_image_path, "JPEG", quality=95)
    
    print(f"测试图像已创建: {test_image_path}")

if __name__ == "__main__":
    main()
